package cn.gok.springboot.controller;

import cn.gok.springboot.pojo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.InternalResourceView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @ClassName FirstController
 * @Description TODO
 * @Author HP
 * @Date 9:19 2022/7/14
 * @Version 1.0
 **/
@RestController//组合标签：@RestController是@ResponseBody和@Controller的组合注解。
public class FirstController {
    @Autowired
    private Student student;

    @RequestMapping ("/hello")
    public String hello(){
        return "Hello Oscar";
    }

    @RequestMapping ("/pojo")
    public Student stu(){
        return student;
    }

    @RequestMapping("/view")
    public ModelAndView view(){
        ModelAndView modelAndView=new ModelAndView();
        student.setAge(99);
        student.setName("爱新觉罗·唐");
        modelAndView.addObject("user",student);
        modelAndView.setViewName("index");
        return modelAndView;
    }

}
